<template>
	<view class="content">
		<view v-if="JSON.stringify(orderListMap) != '{}' ||  orderList.length>1 ">
      <view class="record-list" v-if="orderListMap && orderListMap.startChargeSeqStatus==2">
        <view class="record_item">
          <view class="order-id">桩编号：{{orderListMap.connectorId}}</view>
          <view class="item">
            <view class="label">充电开始时间</view>
            <view class="value">{{orderListMap.startTime}}</view>
          </view>
          <view class="item">
            <view class="label">充电电量</view>
            <view class="value">{{orderListMap.totalPower}}度</view>
          </view>
          <view class="item">
            <view class="label">充电金额</view>
            <view class="value">{{orderListMap.elecMoney}}元</view>
          </view>
          <view class="item">
            <view class="label">服务费</view>
            <view class="value">{{orderListMap.seviceMoney}}元</view>
          </view>
          <view class="item real-pay">
            <view class="label">合计</view>
            <view class="value item-price"><text>{{orderListMap.totalMoney}}</text>元</view>
          </view>
        </view>
        <view class="confirm-btn" @click="chargeDetails(orderListMap)">查看详情</view>
      </view>
			<view class="incomplete-list" v-if="orderList.length>=2">
				<view class="record_item" v-for="(item,index) in orderList" :key="index">
					<view class="name">桩编号：{{item.connectorId}} <!-- <text>(特来电都江堰倾城桥充电站)</text> --> </view>
					<view class="time">开始时间：{{item.startTime}}</view>
					<view class="br"></view>
					<!-- 				<view class="record_info">
										<view class="left">加油升数</view>
										<view class="right">{{item.vol}}升</view>
									</view>
									<view class="record_info">
										<view class="left">{{item.prName}}单价</view>
										<view class="right">{{item.price}}元/升</view>
									</view>
									<view class="record_info">
										<view class="left">优惠</view>
										<view class="right">{{item.discAmt}}元</view>
									</view> -->
					<view class="record_info">
						<view class="left">实付</view>
						<view class="right" style="color: #31bd58;">{{item.totalMoney}}元</view>
					</view>
					<view class="submit" @click="chargeDetails(item)">
						查看详情
					</view>
				</view>
			</view>
		</view>
    <empty v-else></empty>
	</view>
</template>

<script>
	import {
		checkChargeOrders,
		checkChargrHaveOrders
	} from '@/api/index'
  import empty from "@/components/empty.vue";
	export default {
    components: {empty},
		data() {
			return {
				openId: uni.getStorageSync('userOpenId'),
				orderList: [], //订单列表
				orderListMap: {},
				chargeSeqStatus: {
					0: '初始',
					1: '启动中',
					2: '充电中',
					3: '停止中',
					4: '已结束',
					5: '失败'
				}
			}
		},
		onLoad(option) {
			// 进行中
			this.getChargrHaveOrders()

		},
		methods: {
			// 查询订单
			// getOrders(type) {
			// 	checkChargeOrders({
			// 		openid: this.openId,
			// 		paidStatus: type ? type : ''
			// 	}).then(res => {
			// 		console.log(res[0], 'checkChargeOrders')
			// 	}).catch(error => {
			// 		console.log(error)
			// 	})
			// },
			chargeDetails(data) {
				uni.navigateTo({
					url: '/pages/panda-charge/close-charge/index?connectorId=' + (this.orderListMap.connectorId ||
						data.connectorId) + '&startChargeSeq=' + (this.orderListMap.startChargeSeq || data
						.startChargeSeq)
				})
			},
			getTime(createTime) {
				var startTime = new Date(createTime); // 开始时间
				var nowTime = new Date(); // 当前时间
				var diff = nowTime.getTime() - startTime.getTime(); // 时间差值（单位为毫秒）
				var days = Math.floor(diff / (24 * 3600 * 1000)); // 计算相差的天数
				var hours = Math.floor(diff % (24 * 3600 * 1000) / (3600 * 1000)); // 计算小时数
				var minutes = Math.floor(diff % (3600 * 1000) / (60 * 1000)); // 计算分钟数
				var seconds = Math.floor(diff % (60 * 1000) / 1000); // 计算秒数
				hours = days == 0 ? hours : hours + 24 * days
				// console.log(hours + "小时" + minutes + "分钟");
				return hours == 0 ? minutes + "分钟" : hours + "小时" + minutes + "分钟"
			},
			// 查询进行中的订单
			getChargrHaveOrders() {
				checkChargrHaveOrders({
					openid: this.openId,
				}).then(res => {

					let data = res.filter(item => item.startChargeSeqStatus == 2)
					console.log(data);
					if (data.length >= 2) {
						this.orderList = data
					} else if (data.length == 1) {
						this.orderListMap = data[0]
					}
				}).catch(error => {
					console.log(error)
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
    padding: 32upx 20upx;

    .record_item {
      background: #ffffff;
      border-radius: 16rpx 16rpx 16rpx 16rpx;
      //padding: 32rpx 32rpx;
      margin-bottom: 20rpx;
      padding-bottom: 20upx;
      .order-id{
        color: #1B1B1B;
        font-size: 28upx;
        padding: 24upx 20upx;
        line-height: 44upx;
        border-bottom: 1px solid #F0F1F2;
      }

      .item{
        box-sizing: border-box;
        padding: 0 20upx;
        line-height: 84upx;
        font-size: 28upx;
        color: #6A6A6A;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .value{
          color: #1B1B1B;
          font-weight: 500;
        }
        .item-price{
          color: #F57546;
        }
      }
      .real-pay{
        font-weight: 500;
        .item-price{
          text{
            margin-right: 8upx;
            font-size: 44upx;
          }
        }
      }

      .name {
        font-size: 34rpx;
        color: #2d2b2a;
        line-height: 48rpx;
        margin-bottom: 8rpx;
        margin-top: 20upx;
        padding: 0 20upx;
        font-weight: 500;

        text {
          font-size: 28rpx;
          color: #2d2b2a;
        }
      }

      .record_info {
        margin: 16rpx 0rpx;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .pr {
          display: inline-block;
          font-size: 26rpx;
          color: #939391;
          line-height: 40rpx;
          text-align: center;
        }

        .card {
          margin-left: 24rpx;
          display: inline-block;
          text-align: center;
          font-size: 26rpx;
          color: #939391;
          line-height: 40rpx;
        }
      }

      .charge-time {
        font-size: 26rpx;
        color: #939391;
        line-height: 36rpx;
      }

      .charge-number {
        font-size: 26rpx;
        color: #939391;
        line-height: 36rpx;
        margin: 16rpx 0rpx;
      }

      //.order-id {
      //	font-size: 26rpx;
      //	color: #939391;
      //	line-height: 36rpx;
      //}

      .record {
        display: flex;
        align-items: center;
        justify-content: space-between;

        .time {
          font-size: 26rpx;
          color: #939391;
          line-height: 36rpx;
        }

        .price {
          font-size: 40rpx;
          font-weight: 500;
          color: #e56646;
          line-height: 44rpx;

          text {
            font-size: 28rpx;
          }
        }
      }
      .order-price{
        margin-top: 20rpx;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .title {
          font-size: 26rpx;
          color: #939391;
          line-height: 36rpx;
        }

        .price {
          font-size: 40rpx;
          font-weight: 500;
          color: #e56646;
          line-height: 44rpx;

          text {
            font-size: 28rpx;
          }
        }
      }
    }


    .confirm-btn{
      position: fixed;
      left: 50%;
      bottom: 80upx;
      width: 700upx;
      line-height: 80upx;
      background: #006241;
      border-radius: 60upx;
      color: #FFFFFF;
      text-align: center;
      transform: translateX(-50%);
    }

		.incomplete-list {
			padding: 24rpx 24rpx 24rpx 24rpx;

			.record_item {
				position: relative;
				padding: 10rpx 32rpx 10rpx 32rpx;
				background: #ffffff;
				box-shadow: 0px 0px 20rpx 0px rgba(135, 165, 216, 0.1);
				// border-radius: 16rpx;
				border-top-left-radius: 16rpx;
				border-top-right-radius: 16upx;
				margin-bottom: 110rpx;

				.name {
					font-size: 34rpx;
					color: #2d2b2a;
					line-height: 48rpx;
					margin-bottom: 8rpx;

					text {
						font-size: 28rpx;
						color: #2d2b2a;
					}
				}

				.time {
					font-size: 26rpx;
					color: #999999;
					line-height: 50rpx;
				}

				.br {
					width: 100%;
					height: 1px;
					// border: 1px solid ;
					background-color: #ededed;
				}

				.record_info {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.left {
						font-size: 30rpx;
						color: #72798e;
						line-height: 72rpx;
					}

					.right {
						font-size: 30rpx;
						line-height: 72rpx;
						color: #333333;
					}
				}

				.submit {
					padding: 0px 30rpx;
					position: absolute;
					bottom: -38px;
					left: 0px;
					right: 0px;
					margin: auto;
					line-height: 75rpx;
					background: #478BFF;
					border-bottom-left-radius: 12rpx;
					border-bottom-right-radius: 12rpx;
					text-align: center;
					font-size: 32rpx;
					color: #FFFFFF;
				}
			}

			.record_item:nth-last-child(1) {
				margin-bottom: 0;
			}
		}

		.hint {
			width: 100%;
			height: 100vh;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 42rpx;
			color: #c0c0c0;
			letter-spacing: 10rpx;
		}
	}
</style>